package com.hhb.juc.stream;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

public class TestStream {

    public static void main(String[] args) {
        Book book1 = new Book(1, "aaa", 34d);
        Book book7 = new Book(1, "aaa", 34d);
        Book book2 = new Book(2, "bbb", 34d);
        Book book3 = new Book(3, "ccc", 76d);
        Book book4 = new Book(4, "ddd", 99.89d);
        Book book5 = new Book(5, "eee", 45.7d);
        Book book6 = new Book(6, "fff", 123.5d);
        Book book8 = new Book(8, "ggg", 123.5d);
        Book book9 = new Book(9, "hhh", 123.5d);
        Book book10 = new Book(10, "iii", 123.5d);
        Book book11 = new Book(11, "jjj", 123.5d);
        Book book12 = new Book(12, "kkk", 123.5d);

        List<Book> bookList = Arrays.asList(book1, book2, book3, book4, book5, book6,book7,book8,book9,book10,book11,book12);
        bookList.stream()
                .filter(book -> book.getId()%2==0)
                .filter(book -> (book.getPrice()>50d))
                .map(b->b.getBookName().toUpperCase())
                .sorted((b1,b2)->b2.compareTo(b1))
                .limit(2)
                .forEach(System.out::println);







        /*Function<String,Integer> function = s -> s.length();
        System.out.println(function.apply("helloworld"));
        Predicate<String> predicate = s -> book1.equals(book7);
        System.out.println(predicate.test("hi"));*/
    }
}
